<template>
  <ul class="catalog-container">
    <li v-for="(item, i) in list" :key="i">
      <span @click="handleClick(item)" :class="{ active: item.active }">{{
        item.name
      }}</span>
      <span  @click="handleClick(item)" v-if="item.aside" class="aside" :class="{ active: item.active }">{{ item.aside }}</span>
      <Catalog :list="item.children" @select="handleClick(item)" />
    </li>
  </ul>
</template>

<script>
export default {
  //传入一个参数，形式是数组，[name:"",active:"true",children:{}]
  name: "Catalog",
  props: {
    list: Array,
    default: () => {},
  },
  methods: {
    handleClick(item) {
      if (!item.active) {
        this.$emit("select", item);
      }
    },
  },
};
</script>

<style scoped lang="less">
@import "~@/styles/var.less";
.catalog-container {
  list-style: none;
  margin: 0;
  padding: 0;
  .catalog-container {
    margin-left: 1em;
  }
  li {
    font-size: 14px;
    min-height: 40px;
    line-height: 40px;
    cursor: pointer;
  }
  .active {
    color: @warn;
    font-weight: 700;
  }
  .aside{
    font-size: 12px;
    margin-left: 1em;
    color: @gray;
  }
}
</style>